module bubble_sort_demo(
	input[3:0] A,
	input[3:0] B,
	input[3:0] C,
	input[3:0] D,
	output reg[3:0] Outa,
	output reg[3:0] Outb,
	output reg[3:0] Outc,
	output reg[3:0] Outd
);

	reg[3:0] temp_a;
	reg[3:0] temp_b;
	reg[3:0] temp_c;
	reg[3:0] temp_d;
	
	always @(A or B or C or D) begin
	
		{temp_a, temp_b, temp_c, temp_d} = {A, B, C, D};
		
		sort(temp_a, temp_c);
		sort(temp_b, temp_d);
		sort(temp_a, temp_b);
		sort(temp_c, temp_d);
		sort(temp_b, temp_c);
		
		{Outa, Outb, Outc, Outd} = {temp_a, temp_b, temp_c, temp_d};
	
	end
	
task sort;

	inout[3:0] x;
	inout[3:0] y;
	reg[3:0] temp;
	
	if(x > y) begin
		temp = x;
		x = y;
		y = temp;
	end

endtask

endmodule
